/***************************************************************************
 *   Copyright (C) 2007 by Ivan Vasić                    *
 *   ivasic@gmail.com                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef BDECODER_H
#define BDECODER_H

class BNode;

class BDictNode;

class BListNode;

class BValueNode;

class QByteArray;

#include <QObject>

/**
 * @class BDecoder
 * @brief B dekoder (B-Decoder) klasa.
 * @author Ivan Vasić<ivasic@gmail.com>
 *
 * Služi za dekodiranje podataka kodiranih B kodom. Za više detalja oko načina kodiranja pogledati http://www.bittorrent.org/
*/

class BDecoder : public QObject
{
		Q_OBJECT

	public:

		BDecoder(const QByteArray& data, quint32 offset = 0);

		~BDecoder();

		/**
		 * @brief Dekodira B-kodirane podatke
		 * 
		 * @param data - Podaci za dekodiranje.
		 * @returns Pointer na koren stabla BNode. @b Obavezno obrisati objekat na koji pokazuje dobijeni pointer kad prestane da bude potreban.
		 */
		BNode* decode();

	private:
		BDictNode* parseDict();

		BListNode* parseList();

		BValueNode* parseInt();

		BValueNode* parseString();

	private:
		const QByteArray& data;

		quint32 offset;
};

#endif
